<?php
namespace App\Providers;


use App\Models\Admin;
use App\Observers\AdminObserver;
use Illuminate\Support\ServiceProvider;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobFailed;
use  Illuminate\Support\Facades\Queue;



class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if ($this->app->environment() !== 'production') {
            $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
        }

//        $this->bootObservers();
//        $this->bootQueues();

    }

    /**
     * @Author: hzwlxy
     * @Email: 120235331@qq.com
     * @Date: 2019/7/4 14:36
     * @Description:添加观察者模型
     */
    private function bootObservers(){
        Admin::observe(AdminObserver::class);
    }


    private function bootQueues(){
        //使用队列的 before 和 after 方法，你能指定任务处理前和处理后的回调处理。在这些回调里正是实现额外的日志记录或者增加统计数据的好时机
                Queue::before(function (JobProcessing $event) {
                    // $event->connectionName
                    // $event->job
                    // $event->job->payload()
                });

                Queue::after(function (JobProcessed $event) {
                    // $event->connectionName
                    // $event->job
                    // $event->job->payload()
                });
                // 失败的队列,写日志
                Queue::failing(function (JobFailed $event) {
                    // $event->connectionName
                    // $event->job
                    // $event->exception
                });

    }

}
